import {
  createRouter as _createRouter,
  createWebHistory
} from 'vue-router'

const pages = import.meta.glob('../pages/*.vue')

const routes = Object.keys(pages).map(path => {
  const name = path.match(/\.\.\/pages(.*)\.vue$/)[1].toLowerCase()
  return {
    path: name === '/home' ? '/' : name,
    components: pages[path] // () => import('../pages/*.vue')
  }
})

console.log(routes)

export function createRouter () {
  return _createRouter ({
    routes,
    history: createWebHistory()
  })
}
